function setCookie (name, value, expireTime) {
  const exp = new Date()
  exp.setTime(exp.getTime() + expireTime)
  document.cookie = name + '=' + escape(value) + ';expires=' + exp.toUTCString()
}

function getCookie (name) {
  if (document.cookie.length > 0) {
    const reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
    const arr = document.cookie.match(reg)
    if (arr) {
      return unescape(arr[2])
    } else {
      return null
    }
  } else {
    return ''
  }
}

function delCookie (name) {
  const exp = new Date()
  exp.setTime(exp.getTime() - 1)
  var cval = getCookie(name)
  if (!cval) {
    document.cookie = name + '=' + cval + ';expires=' + exp.toUTCString()
  }
}
export {
  setCookie,
  getCookie,
  delCookie
}
